package com.woniu.car.controller;



import com.woniu.car.common.ResponseEntity;

import com.woniu.car.exception.ServiceSException;
import com.woniu.car.param.AddSpecParam;
import com.woniu.car.service.impl.TSpecServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 规格组 前端控制器
 * </p>
 *
 * @author chestnuts
 * @since 2021-06-21
 */
@Api(tags = "规格模块")
@RestController
@RequestMapping("/tSpec")
@Slf4j
public class TSpecController {

    @Autowired
    private TSpecServiceImpl specService;

//    @ApiOperation("规格全展示")
//    @GetMapping("/queryAllSpec")
//    public ResponseEntity allSpec(@RequestParam(value = "SpecId") Integer specId) throws GoodsNullException {
//        TSpec byId = specService.getById(specId);
//        if(byId==null){
//            throw new GoodsNullException("该规格不存在");
//        }
//        return null;
//    }

    @ApiOperation("新增规格")
    @PostMapping("/addSpec")
    public ResponseEntity addSpec(@Valid AddSpecParam addSpecParam){
//        ResponseEntity responseEntity;
//        try{
//            responseEntity=specService.addSpec(addSpecParam);
//        }catch (GoodsNullException e){
//            return new ResponseEntity().setCode(200).setMsg("该商品不存在");
//        }
        ResponseEntity responseEntity=specService.addSpec(addSpecParam);
        return responseEntity;
    }

    @ApiOperation("按类别,展示所有规格组")
    @GetMapping("/queryAllSpecByGategory")
    public ResponseEntity queryAllSpecByGategory(@RequestParam(value = "gategoryId") Integer gategoryId) throws ServiceSException {
        ResponseEntity responseEntity = specService.getAllSpecByGategory(gategoryId);
        return responseEntity;
    }


}

